package com.zhang.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhang.entity.PcDrinkEntity;
import com.zhang.service.PcDrinkService;
import com.zhang.utils.PageResult;
import com.zhang.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 
 *
 * @author Haziy
 * @email 1143878025@qq.com
 * @date 2023-03-10 15:04:39
 */
@RestController
@RequestMapping("pcDrink")
public class PcDrinkController {
    @Autowired
    private PcDrinkService pcDrinkService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        List<PcDrinkEntity> page = pcDrinkService.list();

        return R.ok().put("page", page);
    }

    /**
     * @功能: 分页查询
     * @描述:
     **/
    @GetMapping("/findByPage/{page}/{pageSize}")
    public R findByPage(@PathVariable int page,
                        @PathVariable int pageSize) {
        Page<PcDrinkEntity> page1 = pcDrinkService.page(new Page<>(page, pageSize));
        return R.ok().put("page", new PageResult<>(page1.getTotal(), page1.getRecords()));
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		PcDrinkEntity pcDrink = pcDrinkService.getById(id);

        return R.ok().put("pcDrink", pcDrink);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody PcDrinkEntity pcDrink){
		pcDrinkService.save(pcDrink);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody PcDrinkEntity pcDrink){
		pcDrinkService.updateById(pcDrink);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		pcDrinkService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
